<?php
//----------------------------------------------------------------------------//
// File              : V_QuyHoachAdd										  //
// Modification       :														  //
//----------------------------------------------------------------------------//
// Date(yyyy.mm.dd)   Developer                       Action				  //
//----------------------------------------------------------------------------//
// 2007.03.05         Tran Thanh                     Created				  //
//----------------------------------------------------------------------------//
?>
<script language=javascript>
function doUpload() 
{
	if (document.frm.ten_sp.value=="") {
		alert("Tên sản phẩm không được rỗng");
		document.frm.ten_sp.focus();
		return false;
	}
	if (document.frm.thu_tu.value=="") {
		alert("Thứ tự hiển thị không được rỗng");
		document.frm.thu_tu.focus();
		return false;
	}	
	
	var filename = document.frm.userfile.value;
	var dotpos;
	filename = filename.substring(filename.lastIndexOf("\\")+1,filename.length);
	dotpos=filename.lastIndexOf('.');
	ext=filename.substr(dotpos+1,3);
	ext=ext.toLowerCase();
	fname=filename.substr(0,dotpos);
	if (document.frm.userfile.value!="") {
		if(dotpos==-1||dotpos==0){
			alert("Xin lỗi bạn click vào browser để chọn đúng đường dẫn.");
			return false;
		}
	}

	if (ext!="")
		if ((ext!="gif") && (ext!="jpg") && (ext!="png")  && (ext!="bmp")){
			alert("We only accept file format of GIF, JPG, PNG. Please try again.");
			return false;
		}

	return true;
}
function Focus(){
	document.frm.ten_sp.focus();
}
function showImage(urlimage)
{
	
	if(document.frm.userfile.value!=""){
		choseImage(document.frm.userfile.value);
		
	}else{
		choseImage(urlimage);
	}
}


function btnClearImgOnclick(){
	if (document.frm.userfile.value != ""){
		if (confirm("Bạn có muốn xóa ảnh không?")){
			document.frm.previewField.src = "";
			//document.f.chu_thich_anh.value = "";
			document.getElementById("fn").value='';
			document.getElementById("fileIDSpan").innerHTML=
					"<input name=\"userfile\" type=\"file\" id=\"fn\"  size=\"100\" value=\"\" onChange=\" showImage();\"/>";
		}
	}
}

</script>

<?php
include("../fckeditor/fckeditor.php") ;
function V_SanphamAdd(&$arrayData,$mode)
{
	global $arrayError;
	$ulr = "?".MODUL."=sanpham&".ACTION."=".$mode;

	$strButtonLabel ="Ghi lại";
	$strLabel ="Sửa thông tin sản phẩm";
	if ($mode == "Add"){
		$strButtonLabel ="Thêm mới";	
		$strLabel ="Thêm mới sản phẩm";
	}	
	$strHienThi1 = 'checked="checked"';
	$strHienThi0 = '';
	$strTrangthai1 = 'checked="checked"';
	$strTrangthai0 = '';
	$strLoaitien1 = 'checked="checked"';
	$strLoaitien0 = '';
	if($arrayData["hien_thi"]==0 && $mode!="Add"){
		$strHienThi1 = '';
		$strHienThi0 = 'checked="checked"';
	}
	if($arrayData["trang_thai"]==0 && $mode!="Add"){
		$strTrangthai1 = '';
		$strTrangthai0 = 'checked="checked"';
	}
	if($arrayData["loai_tien"]==0 && $mode!="Add"){
		$strLoaitien1 = '';
		$strLoaitien0 = 'checked="checked"';
	}
	
	$cat_id = CM_getParameter("id_loai_sp");
//	htmlentities(
?>
<?= CM_showError() ?>
<?php
	$mo_ta_sp=$arrayData['mo_ta_sp'];
	$chi_tiet_sp=$arrayData['chi_tiet_sp'];
	$anh_sp=$arrayData['anh_sp'];
	$url_image=DIR_UPLOADFILE_IMAGES.$anh_sp;
?>
<style type="text/css">
<!--
.style1 {color: #000099}
.style2 {
	color: #000000;
	font-weight: bold;
}
-->
</style>
<body onLoad="Focus();">
<table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<form enctype="multipart/form-data" action="<?=$ulr?>" method="post" name="frm" id="frm" onSubmit="return doUpload();">
	<input type="hidden" name="id" value="<?=htmlspecialchars($arrayData["id"])?>" />
	<input type="hidden" name="id_loai_sp1" value="<?=$cat_id?>" />
	<input type="hidden" name="curPg" value="<?=CM_getParameter("curPg");?>" />
	<input type="hidden" name="section_id_hidden" value="<?=htmlspecialchars($arrayData["section_id"])?>" />
	<input type=hidden name="id_loai_sp" value="<?=CM_getParameter("id_loai_sp")?>"> 
        <tr>
          <td colspan="2" bgcolor="#FFE59F"  class=bk12-140><div align="center"><font size="3"><b><?=$strLabel?></b></font></div></td>
        </tr>
		 <tr>
          <td width="20%"  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Tên sản phẩm:</font></span><span style="color:#FF0000;">*</span></td>
          <td width="80%" >
          <input name="ten_sp" type="text" id="ten_sp" value="<?=htmlspecialchars($arrayData["ten_sp"])?>" size="50" maxlength="50" />         </td>
        </tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Giá sản phẩm:</font></span></td>
          <td >
         	 <input name="gia_sp" type="text" id="gia_sp" value="<?=htmlspecialchars($arrayData["gia_sp"])?>" size="15" maxlength="50" />
			 &nbsp;&nbsp;
			 <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
         
          </span>
              <label>
              <input name="loai_tien" type="radio" value="1" checked />
VNĐ</label>
              <!--<label>
              <input name="loai_tien" type="radio" value="0" />
USD</label>-->
			<label> &nbsp;&nbsp;&nbsp;Vd: 1000000</label>
          </font> 
		  </td>
        </tr>
		<tr>
        	<td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Giá khuyến mãi:</font></span></td>
            <td >
         	 <input name="gia_sp_km" type="text" id="gia_sp_km" value="<?=htmlspecialchars($arrayData["gia_sp_km"])?>" size="15" maxlength="50" />
			 &nbsp;&nbsp;
			 <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
         
          </span>
              <label>
              <input name="loai_tien_km" type="radio" value="1" checked />
VNĐ</label>
              <!--<label>
              <input name="loai_tien" type="radio" value="0" />
USD</label>-->
          </font> 
		  </td>
        
        </tr>
		<tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Thông tin khuyến mại:</font></span></td>
          <td >
          <input name="ghi_chu" type="text" id="ghi_chu" value="<?=htmlspecialchars($arrayData["ghi_chu"])?>" size="100" maxlength="256" />         </td>
    	</tr>
		<tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Đóng gói:</font></span></td>
          <td >
          <input name="dong_goi" type="text" id="dong_goi" value="<?=htmlspecialchars($arrayData["dong_goi"])?>" size="100" maxlength="256" />         </td>
    	</tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Loại sản phẩm:</span></font></td>
          <td >
			<select name="cat_id_add" style="WIDTH: 200px">
			<? 
				global $db;
				include_once(DIR_MODEL."md_cat_san_pham.class.php");
				$objcatSanpham = new MD_CatSanpham($db);
				$arrayDataCat0 =  array();   
				$arrayDataCat = array();
				$arrayDataCat0 = $objcatSanpham->getByWhere("id,ten_loai_sp,parent_id","parent_id=0","");
				$arrayDataCat = $objcatSanpham->getByWhere("id,ten_loai_sp,parent_id","parent_id<>0","");
				$id_loai_sp = CM_getParameter("id_loai_sp");
				if (!empty($arrayDataCat0)) { 
					foreach ($arrayDataCat0 as $row0)
						{
							$id0=$row0["id"];
							$name0=$row0["ten_loai_sp"];
							if($id0==$id_loai_sp){
								echo"<option value=$id0 style=\"color:#FF6600; font-weight:bold;\" selected>$name0</option>";
							}else{
								echo"<option value=$id0 style=\"color:#FF6600; font-weight:bold;\">$name0</option>";
							}
							
							
								
							foreach($arrayDataCat as $row){
								$id = $row['id'];
								$name = $row['ten_loai_sp'];
								if($row['parent_id']==$row0['id']){
									if($id==$id_loai_sp){
										$selected = "selected";
									}else{
										$selected = "";
									}
									echo"<option value=$id ".$selected.">&nbsp;&nbsp;&nbsp;$name</option>";
								}// end if
							}// end foreach($arrayDataCat as $row){
						}// end foreach ($arrayDataCat0 as $row0)
						unset($arrayDataCat0,$arrayDataCat);
				}
				
				
			?>	
		</select>
		    </td>
        </tr>
		<tr>
          <td width="20%"  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Tên nhà sản xuất:</font></span></td>
          <td width="80%" >
		 
		  <select name="hang_sx" style="WIDTH: 200px">
			<? 
				global $db;
				include_once(DIR_MODEL."md_hang_sx.class.php");
				$objHangsx = new MD_Hangsx($db);
				$arrayDataHangsx =  array(); 
				$arrayDataHangsx = $objHangsx->getByWhere("*","","thu_tu asc");
				$id_hang_sx = $arrayData['hang_sx'];
				if (!empty($arrayDataHangsx)) { 
					foreach ($arrayDataHangsx as $rowHangsx)
						{
							$idHang=$rowHangsx["id"];
							$nameHang=$rowHangsx["ten_hang"];
							if($idHang==$id_hang_sx){
								echo"<option value=$idHang  selected>$nameHang</option>";
							}else{
								echo"<option value=$idHang >$nameHang</option>";
							}
							
						}// end foreach ($arrayDataHangsx as $rowHangsx)
						unset($arrayDataHangsx);
				}
				
				
			?>	
		</select>
		  </td>
        </tr>
		<tr>
          <td width="20%"  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Bảo hành:</font></span></td>
          <td width="80%" >
		  	<label><input name="bao_hanh" type="text" id="bao_hanh" value="<?=htmlspecialchars($arrayData["bao_hanh"])?>" size="3"maxlength="354"/>
		  &nbsp;&nbsp;tháng</label>
		  </td>
        </tr>
		 <TR>
        <TD bgcolor="#FFE59F"><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Thứ tự hiển thị:</font></span><span style="color:#FF0000;">*</span></TD>
        <TD  class=bk12-140>
          <input name="thu_tu" type="text" align="right" id="thu_tu" value="<?=htmlspecialchars($arrayData["thu_tu"])?>" size="4" maxlength="4" />
        </TD>
     	 </TR>
        <tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Hi&#7875;n th&#7883;:</span></font></td>
          <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
         
          </span>
              <label>
              <input name="hien_thi" type="radio" value="1" <?=$strHienThi1?> />
C&oacute;</label>
              <label>
              <input name="hien_thi" type="radio" value="0" <?=$strHienThi0 ?> />
Kh&ocirc;ng</label>
          </font> </td>
        </tr>
		
         <tr>
          <td  bgcolor="#FFE59F"  ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Trạng thái:</span></font></td>
          <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">
         
          </span>
              <label>
              <input name="trang_thai" type="radio" value="1" <?=$strTrangthai1?> />
Còn hàng</label>
              <label>
              <input name="trang_thai" type="radio" value="0" <?=$strTrangthai0?> />
Hết hàng</label>
          </font> </td>
        </tr>
        <tr>
          <td  bgcolor="#FFE59F"  ><span class="style1"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> Ảnh:</font></span></td>
          <td >
		  	<img name='previewField' height="150px" width="150px" id='previewField' border=0 
							src="<?=DIR_UPLOADFILE_IMAGES.$anh_sp?>"  onLoad="showImage('<?=$url_image?>');"  >		  </td>
        </tr>
       
		
		<tr>
          <td  bgcolor="#FFE59F"  >
		  	  <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			  		<span class="style1">Tên ảnh:</span>              </font>		 </td>
		 <td ><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
		  <?
		  	if($mode=="Edit"){
		  ?>
		  		<font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?=htmlspecialchars($arrayData["anh_sp"])?>
		 </font><br>
		 <?
		 	}else{}
		 ?>
		 	<span id="fileIDSpan">
            <input name="userfile" type="file" id="fn"  size="80" value="<?=htmlspecialchars($arrayData["anh_sp"])?>" onChange=" showImage();"/>
          </span></font>		  </td>
    </tr>
		
	
	<tr>
		<td class="style1" bgcolor="#FFE59F">
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Mô tả: </font>		</td>
		<td>
         <?php
			// Automatically calculates the editor base path based on the _samples directory.
			// This is usefull only for these samples. A real application should use something like this:
			// $oFCKeditor->BasePath = '/fckeditor/' ;    // '/fckeditor/' is the default value.
			//$_SERVER : is an array containing information such as headers, paths, and script locations.
			//           The entries in this array are created by the web server.
			//           This is a automatic global, variable. This simply means that it is available in all scopes throughout a script.
			//           You don't need to do a global $_SERVER; to access it within functions or methods,
			//'PHP_SELF' : The filename of the currently executing script, relative to the document root.
			//             For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
			//             would be /test.php/foo.bar. The __FILE__  constant contains the full path and filename of the current (i.e. included) file.
			// Lay ve duong dan chinh cua server.
			$sBasePath = $_SERVER['PHP_SELF'] ;
			// Lay ve thu muc goc cho den _sample.
			$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "run" ) ) ;
			
			$sBasePath = $sBasePath."fckeditor/";
			$oFCKeditor = new FCKeditor('mo_ta_sp') ;
			$oFCKeditor->BasePath    = $sBasePath ;
			$oFCKeditor->Width        = '100%' ;
			$oFCKeditor->Height        = '300' ;
			$oFCKeditor->Value       = $mo_ta_sp;
			$oFCKeditor->Create() ;
			?>	  </td>
	</tr>
    <tr>
		<td class="style1" bgcolor="#FFE59F">
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Chi tiết: </font>		</td>
		<td>
         <?php
			// Automatically calculates the editor base path based on the _samples directory.
			// This is usefull only for these samples. A real application should use something like this:
			// $oFCKeditor->BasePath = '/fckeditor/' ;    // '/fckeditor/' is the default value.
			//$_SERVER : is an array containing information such as headers, paths, and script locations.
			//           The entries in this array are created by the web server.
			//           This is a automatic global, variable. This simply means that it is available in all scopes throughout a script.
			//           You don't need to do a global $_SERVER; to access it within functions or methods,
			//'PHP_SELF' : The filename of the currently executing script, relative to the document root.
			//             For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
			//             would be /test.php/foo.bar. The __FILE__  constant contains the full path and filename of the current (i.e. included) file.
			// Lay ve duong dan chinh cua server.
			$sBasePath = $_SERVER['PHP_SELF'] ;
			// Lay ve thu muc goc cho den _sample.
			$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "run" ) ) ;
			
			$sBasePath = $sBasePath."fckeditor/";
			$oFCKeditor = new FCKeditor('chi_tiet_sp') ;
			$oFCKeditor->BasePath    = $sBasePath ;
			$oFCKeditor->Width        = '100%' ;
			$oFCKeditor->Height        = '600' ;
			$oFCKeditor->Value       = $chi_tiet_sp;
			$oFCKeditor->Create() ;
			?>	  </td>
	</tr>
	 
	
				<script language = 'JavaScript' >
				function backToList(){
					location = '<? echo "?".MODUL."=sanpham&".ACTION."=List&id_loai_sp=$cat_id&curPg=".CM_getParameter("curPg")."";?>';
					return;
				}
				</script>
				<tr>
					<td colspan="2" align="center">
						<input name="Reset" type="reset" value="Nhập lại" />
						<input name="Submit" type="submit" value="<?=$strButtonLabel?>" />
						<input type="button" name="back" value="Trở lại "
						onClick="javascript: return backToList();">
										</td>
				</tr>
			</tbody>
<input type=hidden name="modul" value="<?=CM_getParameter("modul")?>"> 
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>">
<input type=hidden name="id_loai_spS" value="<?=CM_getParameter("id_loai_spS")?>"> 
<input type=hidden name="id_loai_sp" value="<?=CM_getParameter("id_loai_sp")?>"> 
<input type=hidden name="section_idS" value="<?=CM_getParameter("section_idS")?>"> 
<input type=hidden name="showsS" value="<?=CM_getParameter("showsS")?>"> 
</form>
</table>
</body>
<script language="javascript">
	setSelectOptions("frm","section_id","section_id_hidden");
</script>

<?php
}
?>
